package com.huluobo.day11_im.splash.view;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;

import com.huluobo.day11_im.activity.MainActivity;
import com.huluobo.day11_im.R;
import com.huluobo.day11_im.login.view.LoginActivity;
import com.huluobo.day11_im.splash.presenter.SplashContract;
import com.huluobo.day11_im.splash.presenter.SplashPresenter;
import com.huluobo.day11_im.weight.MyView;

public class SplashActivity extends AppCompatActivity implements SplashContract.View {

    private SplashPresenter splashPresenter;

    private MyView myView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        splashPresenter = new SplashPresenter(this);
        myView = findViewById(R.id.myView);
        myView.setOnAnimEndListener(new MyView.OnAnimEndListener() {
            @Override
            public void onAnimEnd() {
                splashPresenter.checkIsLoggedInBefore();
            }
        });
        myView.start(1);
    }

    @Override
    public void isLoggedIn() {
        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
        startActivity(intent);
    }

    @Override
    public void isNotLoggedIn() {
        Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
        startActivity(intent);
    }
}